<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <div v-for="item in arr" :key="item">{{item}}</div>
      <div>{{obj.name}}</div>
      <div>{{obj.age}}</div>
    </div>
    <script>
      class Vue {
        constructor(options) {
          //判断当前是否有el属性 来渲染模板
          this.$options = options;
          //处理el
          if (this.$options.el) {
            this.$mount(this.$options.el);
          }
        }
        //处理$mount('id')
        $mount(el) {
          const vm = this;
          const options = vm.$options;
          el = document.querySelector(el);
          console.log(el, options); //获取到当前跟节点
          if (!options.render) {
            //没有render 将template转化为render
            console.log(options);
            let template = options.template;
            if (!template && el) {
              //tempale与render都没有传
              template = el.outerHTML;
            }
            const render = compileToFunction(template); //编译模板 将template编译成render
            console.log(template);
          }
        }
      }
      new Vue({
        el: '#app',
        data: {
          arr: [1, 2, 3],
          obj: {
            name: '你好',
            age: 18,
          },
        },
        template: '<div>22</div>',
      });
      // vm.$mount('#a pp')
    </script>
  </body>
</html>
